/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 26727
 * Date: 2024-01-10
 * Time: 13:09
 */
//泛型的上界
/** class Arg<E extends Comparable<E>> {
    public E findMax(E[] array) {
        E max = array[0];
        for(int i = 0; i < array.length; i++) {
            if(max.compareTo(array[i]) < 0) {
                max = array[i];
            }
        }
        return max;
    }
}
public class Demo2 {
    public static void main(String[] arg) {
       Arg<Integer> alg =new Arg<>();
       Integer[] array = {1,3,8,14};
       Integer val = alg.findMax(array);
       System.out.println(val);
    }

} */

//泛型的方法
class Arg {
    public static <E extends Comparable<E>> E findMax(E[] array) {
        E max = array[0];
        for(int i = 0; i < array.length; i++) {
            if(max.compareTo(array[i]) < 0) {
                max = array[i];
            }
        }
        return max;
    }
}
public class Demo2 {
    public static void main(String[] arg) {
        Integer[] array = {1,3,8,14};
        Integer val = Arg.<Integer>findMax(array);
        System.out.println(val);
    }

}

//补充内容
/** class A<E extends Number> {

}

public class Test1 {
    public static void main(String[] arg) {
        Arg<Integer> a1 =new A<>();
        Arg<Double> a2 =new A<>();
        //Arg<Stringr> a3 =new A<>(); 不可以,Number子类没有String
    }

}*/
